package org.tea.inventory.db.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.tea.inventory.db.dao.QuestionSortMapper;
import org.tea.inventory.db.domain.QuestionSort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * PK问题的种类
 */
@Service
public class QuestionSortService {

    @Resource
    private QuestionSortMapper questionSortMapper;

    /**
     * 返回问题数量大于等于num的问题种类sort
     * @param num
     * @return
     */
    public List<QuestionSort> selectSortEnough(Integer num){
        return questionSortMapper.selectSortEnough(num);
    }

    public Map<String, Object> selectByExample(QuestionSort record,Integer page,Integer size){
        PageHelper.startPage(page, size);
        List<QuestionSort> list = null;
        list = questionSortMapper.selectByExample(record);
        PageInfo pageinfo = new PageInfo(list);
        Map<String,Object> resMap = new HashMap<String,Object>();
        resMap.put("pageNum",pageinfo.getPageNum());
        resMap.put("pageSize", pageinfo.getPageSize());
        resMap.put("startRow", pageinfo.getStartRow());
        resMap.put("endRow", pageinfo.getEndRow());
        resMap.put("total", pageinfo.getTotal());
        resMap.put("pages", pageinfo.getPages());
        resMap.put("items", list);
        return resMap;
    }

    public int deleteByPrimaryKey(Integer id){
        return questionSortMapper.deleteByPrimaryKey(id);
    }

    public int insert(QuestionSort record){
        return questionSortMapper.insert(record);
    }

    public int insertSelective(QuestionSort record){
        return questionSortMapper.insertSelective(record);
    }

    public QuestionSort selectByPrimaryKey(Integer id){
        return questionSortMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(QuestionSort record){
        return questionSortMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(QuestionSort record){
        return questionSortMapper.updateByPrimaryKey(record);
    }

    /**
     * 更新某个问题种类的已有问题数量
     * @param id
     * @return
     */
    public int updateQuestionNumByPrimaryKey(Integer id){
        return questionSortMapper.updateQuestionNumByPrimaryKey(id);
    }

}
